import requests

text_filter_api = "http://localhost:9191/api/text-filter"
text_replace_api = "http://localhost:9191/api/text-replace"

def get_dirty_words(text):
    risks = ""
    body = 'txt='+text
    headers = {}
    headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"
    req = requests.post(text_filter_api,data=body.encode('utf-8'),headers=headers)
    if req.json():
        result = req.json()
        if result["riskLevel"] != "PASS":
            risks = result['details'][0]["text"]
    return risks

def get_dirty_remove_words(text):
    risks = ""
    body = 'txt='+text
    headers = {}
    headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"
    req = requests.post(text_replace_api,data=body.encode('utf-8'),headers=headers)
    if req.json():
        result = req.json()
        if "resultText" in result:
            risks = result['resultText']
        elif result['riskLevel'] == "PASS":
            risks = text
    return risks



if __name__ == '__main__':
    print(get_dirty_remove_words("你真是个撒比"))